#coding=utf-8
import os
import sys
import shutil
basepath='C:\\EsriPress\\Python\\Data'
# os.chdir(basepath)
filename=[]
def getfile(path):
    # print('查找路径为：%s'%path)
    # os.chdir(path)
    # print(os.getcwd())
    # pathlist=os.listdir(path)
    # for each in pathlist:
    #     if os.path.isdir(each):
    #         getfile(each)
    #         os.chdir(os.pardir)
    #     else:
    #         filename.append(os.path.join(os.curdir,each))
    # return filename
    all=os.walk(path)
    for each in all:
        for eachfile in each[2]:
            if eachfile !=[]:
                filename.append(each[0]+os.path.sep+eachfile)
# def movfile(filename,newpath='c:\\Data'):
#     if not os.path.exists(newpath):
#         os.mkdir(newpath)
#     for eachfile in filename:
#         shutil.move(eachfile,newpath)
getfile(basepath)
for eachfile in filename:
    # print(eachfile)
    if not os.path.exists('c:\Data\\'+str.split(eachfile,'\\')[-1]):
        shutil.move(eachfile,'c:\\Data\\')
        print('成功复制文件%s'%eachfile)
    else:
        # print('文件%s已存在！'%eachfile)
        continue
# print(filename)